home *** CD-ROM | disk | FTP | other *** search
/ Champak 132 (Alt) / Vol 132.iso / games / 3d_hyper / 3d_hyper.dcr / Scripts_1_gameFrameScript.ls < prev    next >
Encoding:
Text File  |  2011-06-09  |  4.4 KB  |  150 lines

  1. property pLastFrameTime, pCheckMovementTimeout, pFrameTimes, pFinishedTime, pBeginTime
  2. global gCamera, gCar, gWorld, gRacers, gHaveSound, gSparkLocs, gSparkCount, gSparkSystems, gCollDetails, gLastTrackCollision, gLastCarCollision, gFinished, gFrameRate, gTimeStep, gHavok, gLastCollSound, gCurrentVel
  3.  
  4. on beginSprite me
  5.   pLastFrameTime = the milliSeconds
  6.   pFrameTimes = []
  7.   repeat with i = 1 to 30
  8.     add(pFrameTimes, the milliSeconds)
  9.   end repeat
  10.   pBeginTime = the milliSeconds
  11.   gCar = gWorld.model("carModel_1")
  12. end
  13.  
  14. on exitFrame
  15.   checkForExit()
  16.   checkForMovement()
  17.   if gHaveSound then
  18.     if not sound(1).isBusy() then
  19.       sound(1).play(member("cracermusic"))
  20.     end if
  21.   end if
  22.   add(pFrameTimes, the milliSeconds)
  23.   deleteAt(pFrameTimes, 1)
  24.   timePerFrame = (pFrameTimes[pFrameTimes.count] - pFrameTimes[1]) / float(pFrameTimes.count)
  25.   if timePerFrame < 10 then
  26.     timePerFrame = 10
  27.   else
  28.     if timePerFrame > 100 then
  29.       timePerFrame = 100
  30.     end if
  31.   end if
  32.   gTimeStep = timePerFrame / 1000.0
  33.   gFrameRate = 1000.0 / timePerFrame
  34.   if gRacers[1].pCourseTime then
  35.     if pFinishedTime then
  36.       if (the milliSeconds - pFinishedTime) > 1500 then
  37.         the timeOutList = []
  38.         go("Course Screen")
  39.       else
  40.         go(the frame)
  41.       end if
  42.     else
  43.       if gCurrentVel.magnitude < 50 then
  44.         pFinishedTime = the milliSeconds
  45.       end if
  46.       go(the frame)
  47.     end if
  48.   else
  49.     if gFinished then
  50.       the timeOutList = []
  51.       stopSounds()
  52.       gCurrTrack = gCurrTrack - 1
  53.       go("Tweak Car")
  54.     else
  55.       go(the frame)
  56.     end if
  57.   end if
  58. end
  59.  
  60. on prepareFrame me
  61.   timeElapsed = the milliSeconds - pLastFrameTime
  62.   currTime = the milliSeconds
  63.   repeat with i = 1 to gRacers.count
  64.     gRacers[i].updateCarFloat()
  65.   end repeat
  66.   updateCamera()
  67.   updateSpeedometer()
  68.   checkCollisions()
  69.   checkPowerups()
  70.   updateSky()
  71.   pLastFrameTime = the milliSeconds
  72. end
  73.  
  74. on playCollisionSound theSound, theLoc
  75.   if gHaveSound then
  76.     gLastCollSound = gLastCollSound + 1
  77.     if gLastCollSound > 4 then
  78.       gLastCollSound = 3
  79.     end if
  80.     tempVec = gCar.worldPosition - theLoc
  81.     tempVec.normalize()
  82.     rightDot = gRacers[1].pWorldRight.dot(tempVec)
  83.     myPan = 100 * rightDot
  84.     sound(gLastCollSound).stop()
  85.     sound(gLastCollSound).setPlayList([[#member: member(theSound)]])
  86.     sound(gLastCollSound).play()
  87.     sound(gLastCollSound).volume = 140
  88.     sound(gLastCollSound).pan = myPan
  89.   end if
  90. end
  91.  
  92. on getTimePassed me
  93.   return the milliSeconds - pBeginTime
  94. end
  95.  
  96. on checkCollisions
  97.   if gCollDetails.count > 0 then
  98.     repeat with i = 1 to gCollDetails.count
  99.       if gCollDetails[i][2] contains "track" then
  100.         if gCurrentVel.magnitude > 50 then
  101.           if (the milliSeconds - gLastTrackCollision) > 1000 then
  102.             playCollisionSound("scrape", gCollDetails[i][3])
  103.             gLastTrackCollision = the milliSeconds
  104.           end if
  105.         end if
  106.         next repeat
  107.       end if
  108.       if (the milliSeconds - gLastCarCollision) > 300 then
  109.         playCollisionSound("impactshrt", gCollDetails[i][3])
  110.         gLastCarCollision = the milliSeconds
  111.       end if
  112.     end repeat
  113.     gCollDetails = []
  114.   end if
  115.   repeat with i = gSparkLocs.count down to 1
  116.     theLoc = gSparkLocs[i]
  117.     theSin = sin(-gRacers[1].pTurnData.currentTurn / 180 * PI)
  118.     theCos = cos(-gRacers[1].pTurnData.currentTurn / 180 * PI)
  119.     theNewLoc = vector(0, 0, 0)
  120.     theNewLoc.x = (theCos * theLoc.x) + (theSin * theLoc.z)
  121.     theNewLoc.z = (theSin * theLoc.x) + (theCos * theLoc.z)
  122.     gSparkCount = gSparkCount + 1
  123.     ts = gWorld.newModelResource("SparkSystem_" & gSparkCount, #particle)
  124.     ts.sizeRange.start = 0.10000000000000001
  125.     ts.sizeRange.end = 0.20000000000000001
  126.     ts.lifeTime = 750
  127.     ts.emitter.minSpeed = 60
  128.     ts.emitter.maxSpeed = 80
  129.     ts.colorRange.end = rgb("FF9900")
  130.     ts.colorRange.start = rgb("FFFF00")
  131.     ts.emitter.angle = 5
  132.     ts.emitter.direction = vector(0, 0, 1)
  133.     ts.emitter.numParticles = 7
  134.     ts.emitter.mode = #burst
  135.     ts.emitter.loop = 0
  136.     tm = gWorld.newModel("SparkModel_" & gSparkCount, ts)
  137.     tm.transform.position = theNewLoc
  138.     tm.parent = gCar.parent
  139.     add(gSparkSystems, tm)
  140.     deleteAt(gSparkLocs, i)
  141.   end repeat
  142.   if gSparkSystems.count > 20 then
  143.     repeat with i = gSparkSystems.count - 20 down to 1
  144.       gWorld.deleteModelResource(gSparkSystems[i].resource.name)
  145.       gWorld.deleteModel(gSparkSystems[i].name)
  146.       deleteAt(gSparkSystems, i)
  147.     end repeat
  148.   end if
  149. end
  150.